package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.HDResultVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DResult;
import com.ruoyi.system.service.IDResultService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 追溯结果Controller
 * 
 * @author ruoyi
 * @date 2025-02-16
 */
@RestController
@RequestMapping("/system/result")
public class DResultController extends BaseController
{
    @Autowired
    private IDResultService dResultService;

    /**
     * 查询追溯结果列表
     */
    @PreAuthorize("@ss.hasPermi('system:result:list')")
    @GetMapping("/list")
    public TableDataInfo list(DResult dResult)
    {
        startPage();
        List<DResult> list = dResultService.selectDResultList(dResult);
        return getDataTable(list);
    }

    /**
     * 导出追溯结果列表
     */
    @PreAuthorize("@ss.hasPermi('system:result:export')")
    @Log(title = "追溯结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DResult dResult)
    {
        List<DResult> list = dResultService.selectDResultList(dResult);
        ExcelUtil<DResult> util = new ExcelUtil<DResult>(DResult.class);
        util.exportExcel(response, list, "追溯结果数据");
    }

    /**
     * 获取追溯结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:result:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(dResultService.selectDResultByID(ID));
    }

    /**
     * 新增追溯结果
     */
    @PreAuthorize("@ss.hasPermi('system:result:add')")
    @Log(title = "追溯结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DResult dResult)
    {
        return toAjax(dResultService.insertDResult(dResult));
    }

    /**
     * 修改追溯结果
     */
    @PreAuthorize("@ss.hasPermi('system:result:edit')")
    @Log(title = "追溯结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DResult dResult)
    {
        return toAjax(dResultService.updateDResult(dResult));
    }

    /**
     * 删除追溯结果
     */
    @PreAuthorize("@ss.hasPermi('system:result:remove')")
    @Log(title = "追溯结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(dResultService.deleteDResultByIDs(IDs));
    }

    @GetMapping("/hd_list")
    public TableDataInfo hd_list(HDResultVo hdResultVo)
    {
        dResultService.createResult_HD(hdResultVo);
        startPage();
        List<HDResultVo> list = dResultService.selectResultList_HD(hdResultVo);
        return getDataTable(list);
    }

}
